package com.gzist.elderlyserviceplatform.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gzist.elderlyserviceplatform.entity.dto.InfoNamePageDTO;
import com.gzist.elderlyserviceplatform.entity.po.InfoCategory;
import com.gzist.elderlyserviceplatform.mapper.InfoCategoryMapper;
import com.gzist.elderlyserviceplatform.service.InfoCategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * 资讯分类表 服务实现类
 */
@Service
public class InfoCategoryServiceImpl extends ServiceImpl<InfoCategoryMapper, InfoCategory> implements InfoCategoryService {

    @Override
    public Page<InfoCategory> queryPage(InfoNamePageDTO dto) {
        LambdaQueryWrapper<InfoCategory> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(InfoCategory::getDelFlag, 0)
                .orderByDesc(InfoCategory::getUpdateTime);
        if (StrUtil.isNotBlank(dto.getName())) {
            wrapper.like(InfoCategory::getName, dto.getName());
        }
        return this.page(new Page<>(dto.getPageNum(), dto.getPageSize()), wrapper);
    }

}
